﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ShareMarking.Service;
using ShareMarking.Entity;

namespace ShareMarking.Interface
{
    public class qrCodeManage
    {
        protected string httpstr;
        protected string signsecret;

        public qrCodeManage(string http, string sign)
        {
            this.httpstr = http;
            this.signsecret = sign;
        }

        

        //public void ManageHospQr()
        //{
        //    //先得到所有的医院
        //    var hplist = sfdc_HospitalService.Instance.Get_AllData_List();

        //    hplist.ForEach(o =>
        //    {
        //        var has = qr_QrCodeRelateService.Instance.Get_IsExist_ByWhere(
        //            qr_QrCodeRelate._.qr_Type == 2 && qr_QrCodeRelate._.rel_Code == o.Code__c);

        //        if (!has)//如果在关联表没有医院对应的记录，就新增二维码
        //        {
        //            var sceneid = 0;
        //            qr_QrCodeType type = qr_QrCodeTypeService.Instance.Get_SingleEntity_byWhere(qr_QrCodeType._.QrCodeTypeID == 2);
        //            sceneid = type.QT_CurrentIndex.ConvertTo<int>() + 1;
        //            type.QT_CurrentIndex = sceneid;

        //            var extra = new List<extra>() { 
        //                new extra { 
        //                    title = "【美赞臣】微信注册", 
        //                    shortdesc = "注册成为会员，享受更多优惠折扣！", 
        //                    linkurl = "http://svr.meadjohnson.com.cn/mjnwx/client_phone.action?NCCode="+o.Code__c+o.MSR_StaffID__c+"$openId=####", 
        //                    picurl = "http://svr.meadjohnson.com.cn/mjnwx/css/images/logo_b.png" 
        //                }
        //            };
        //            var message = new message()
        //            {
        //                title = o.Name__c,
        //                remark = o.Name__c + "的二维码",
        //                sacode = "test",
        //                scene_id = sceneid.ToString(),
        //                extra = extra
        //            };
        //            var resultentity = new Qrcode_vigo().CreateQrcode(this.httpstr, this.signsecret, message);

        //            if (resultentity.errcode == "00")
        //            {
        //                qr_QrCode qrcode = new qr_QrCode()
        //                {
        //                    id = resultentity.message.id,
        //                    type = 2,
        //                    scene_id = resultentity.message.scene_id,
        //                    sacode = resultentity.message.sacode,
        //                    title = resultentity.message.title,
        //                    remark = resultentity.message.remark,
        //                    code_url = resultentity.message.code_url,
        //                    qrcode_url = resultentity.message.qrcode_url,
        //                    addtime = resultentity.message.addtime,
        //                    status = resultentity.message.status,
        //                    isdelete = false
        //                };
        //                qr_QrCodeService.Instance.Add_Entity(qrcode);
        //            }

        //            //添加关联
        //            qr_QrCodeRelate qrrelate = new qr_QrCodeRelate()
        //            {
        //                qr_Type = 2,//2是医院
        //                qr_CodeID = resultentity.message.id,
        //                qr_Scene_ID = resultentity.message.scene_id,
        //                rel_Code = o.Code__c,
        //                IsDelete = false,
        //                CreateOn = DateTime.Now
        //            };
        //            qr_QrCodeRelateService.Instance.Add_Entity(qrrelate);
        //            qr_QrCodeTypeService.Instance.Update_Entity(type);
        //        }
        //    });
        //}

        //public void UpdateHospQr()
        //{
        //}

        //public void ManagePNRQr()
        //{
        //    //先得到所有的PNR
        //    var hplist = sfdc_PNRService.Instance.Get_AllData_List();

        //    hplist.ForEach(o =>
        //    {
        //        var has = qr_QrCodeRelateService.Instance.Get_IsExist_ByWhere(
        //            qr_QrCodeRelate._.qr_Type == 3 && qr_QrCodeRelate._.rel_Code == o.EmployeeNumber__c);

        //        if (!has)//如果在关联表没有医院对应的记录，就新增二维码
        //        {
        //            var sceneid = 0;
        //            qr_QrCodeType type = qr_QrCodeTypeService.Instance.Get_SingleEntity_byWhere(qr_QrCodeType._.QrCodeTypeID == 3);
        //            sceneid = type.QT_CurrentIndex.ConvertTo<int>() + 1;
        //            type.QT_CurrentIndex = sceneid;

        //            var extra = new List<extra>() { 
        //                new extra { 
        //                    title = "【美赞臣】微信注册", 
        //                    shortdesc = "注册成为会员，享受更多优惠折扣！", 
        //                    linkurl = "http://svr.meadjohnson.com.cn/mjnwx/client_phone.action?NCCode="+o.EmployeeNumber__c+"$openId=####", 
        //                    picurl = "http://svr.meadjohnson.com.cn/mjnwx/css/images/logo_b.png" 
        //                }
        //            };
        //            var message = new message()
        //            {
        //                title = o.Name__c,
        //                remark = o.Name__c + "的二维码",
        //                sacode = "test",
        //                scene_id = sceneid.ToString(),
        //                extra = extra
        //            };
        //            var resultentity = new Qrcode_vigo().CreateQrcode(this.httpstr, this.signsecret, message);

        //            if (resultentity.errcode == "00")
        //            {
        //                qr_QrCode qrcode = new qr_QrCode()
        //                {
        //                    id = resultentity.message.id,
        //                    type = 3,
        //                    scene_id = resultentity.message.scene_id,
        //                    sacode = resultentity.message.sacode,
        //                    title = resultentity.message.title,
        //                    remark = resultentity.message.remark,
        //                    code_url = resultentity.message.code_url,
        //                    qrcode_url = resultentity.message.qrcode_url,
        //                    addtime = resultentity.message.addtime,
        //                    status = resultentity.message.status,
        //                    isdelete = false
        //                };
        //                qr_QrCodeService.Instance.Add_Entity(qrcode);
        //            }

        //            //添加关联
        //            qr_QrCodeRelate qrrelate = new qr_QrCodeRelate()
        //            {
        //                qr_Type = 3,//3是PNR
        //                qr_CodeID = resultentity.message.id,
        //                qr_Scene_ID = resultentity.message.scene_id,
        //                rel_Code = o.EmployeeNumber__c,
        //                IsDelete = false,
        //                CreateOn = DateTime.Now
        //            };
        //            qr_QrCodeRelateService.Instance.Add_Entity(qrrelate);
        //            qr_QrCodeTypeService.Instance.Update_Entity(type);
        //        }
        //    });
        //}
    }
}
